package org.flower.httprc;

import java.io.IOException;
import java.net.URL;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import org.flower.httprc.util.JavaUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * JavaFX App
 */
public class HttpRClientApp extends Application {

    private static final Logger LOG = LoggerFactory.getLogger(HttpRClientApp.class);
    private static Scene scene;

    @Override
    public void start(Stage primaryStage) throws Exception {
        LOG.info("----Flower HttpR~Client StartUp----");
        primaryStage.setTitle("Flower HttpRClient");
        primaryStage.initStyle(StageStyle.DECORATED);

        Parent root = loadFXML("flower-httprc");
        scene = new Scene(root);
        primaryStage.setScene(scene);
        System.out.println("imo:" + JavaUtil.loadUrl("images/mo.png").toString());
        Image icon = new Image("images/mo.png");
        primaryStage.getIcons().add(icon);
        primaryStage.show();
    }

    private static Parent loadFXML(String fxml) throws IOException {
        URL url = JavaUtil.loadUrl("fxml/" + fxml + ".fxml");
        FXMLLoader fxmlLoader = new FXMLLoader(url);
        return fxmlLoader.load();
    }

    public static void main(String[] args) {
        launch(args);
    }
}
